const ws = new WebSocket('ws://localhost:8000')//链接websocket服务端

//上线
ws.onopen =  () => {
    ws.send("我上线了")
}
//发送消息
ws.onmessage = (msg) => {
    console.log(msg);

    //js原生语法从页面DOM对象中动态获取说话内容
    const content = document.getElementById('content')
    content.innerHTML += msg.data + '<br/>'
}

//报错
ws.onerror = (err) => {
    console.log(err)
}

//下线

ws.onclose = () => {
    console.log('close')
}